package com.chuhe.starry.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chuhe.common.domain.entity.ChatMessage;
import com.chuhe.common.domain.vo.resp.loadContactResp;
import com.chuhe.starry.mapper.ChatMessageMapper;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
 * <p>
 * 聊天消息表 服务实现类
 * </p>
 *
 * @author 张楚河
 * @since 2025-05-21
 */
@Service
public class ChatMessageDao extends ServiceImpl<ChatMessageMapper, ChatMessage> {

    /**
     * 查询所有消息（三天）
     * @Author: 楚河
     * @Date: 2025-05-21 22:37
     */
    public List<ChatMessage> selectAllMessage(List<String> contactId,Long lastOffTime) {
        return lambdaQuery()
                .in(ChatMessage::getContactId, contactId)
                .ge(lastOffTime != 0,ChatMessage::getSendTime,lastOffTime)
                .orderByAsc(ChatMessage::getSendTime)
                .list();
    }
    /**
     * 根据id查找
     * @Author: 楚河
     * @Date: 2025-05-24 16:47
     */
    public ChatMessage selectById(Long messageId) {
        return lambdaQuery()
                .eq(ChatMessage::getMessageId, messageId)
                .one();
    }
    /**
     * 修改状态
     * @Author: 楚河
     * @Date: 2025-05-24 16:52
     */
    public void updateByParam(ChatMessage updateInfo, Long messageId) {
        lambdaUpdate()
                .eq(ChatMessage::getMessageId,messageId)
                .set(ChatMessage::getStatus,updateInfo.getStatus())
                .update();
    }
}
